﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
#if NETFX_CORE
using Windows.ApplicationModel.Resources;

#endif

namespace StyleMVVM.Validation.Impl.Fluent.Operators
{
	public class GreaterThanOperator<T> : BinaryOperator<T>
	{
		public GreaterThanOperator()
		{
			expressionMethod = GetType().GetTypeInfo().GetDeclaredMethod("Operate");
		}

#if NETFX_CORE
		public override string GenerateLogicStatement(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "IsGreaterThan");
		}

		public override string GenerateErrorMessage(ResourceLoader fluentResources)
		{
			return InternalGenerateMessage(fluentResources, "MustBeGreaterThan");
		}
#else
		public override string GenerateLogicStatement()
		{
			return InternalGenerateMessage(FluentResources.IsGreaterThan);
		}

		public override string GenerateErrorMessage()
		{
			return InternalGenerateMessage(FluentResources.MustBeGreaterThan);
		}
#endif

		public static bool Operate(object leftValue, object rightValue)
		{
			IComparable compareLeft = leftValue as IComparable;
			IComparable compareRight = rightValue as IComparable;

			if (compareLeft != null)
			{
				if (compareRight != null)
				{
					return compareLeft.CompareTo(compareRight) > 0;
				}

				return true;
			}

			return false;
		}
	}
}